package com.my.geojson.geotools.controller;

import com.my.geojson.geotools.service.test.TestService;
import com.my.geojson.mybatis.test.entity.Test;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController("erq")
@RequestMapping("geotools")
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping("test")
    public Object test(){
        return testService.addPointFeature(
                108.21,38.34,Test.class);
    }

    @RequestMapping("test2")
    public Object test2(){
        Test test = new Test();
        test.setName("张三");
        test.setLocation("四川成都");
        test.setLnglat(Arrays.asList("2.1","2.2","3.3").toArray(new String[3]));

        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
        Point point = geometryFactory.createPoint(new Coordinate(108.21,38.34));

        test.setLnglatGeom(point);
        return testService.addFeature(test,Test.class);
    }

    @RequestMapping("remove")
    public Object remove(){
        return testService.removeFeatureByName("张三",Test.class);
    }

    @RequestMapping("query")
    public Object query(){
        return testService.queryFeature("name = '张三'",Test.class);
    }
    @RequestMapping("modify")
    public Object modify(){
        return testService.modifyFeature("",Test.class);
    }

}
